import router from './router';
import store from './store';
import {Message} from 'element-ui';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css'; // progress bar style
import {getToken} from '@/utils/auth'; // get token from cookie
import getPageTitle from '@/utils/get-page-title';

import { getLoginUrl } from '@/api/public'

NProgress.configure({showSpinner: false}); // NProgress Configuration

const whiteList = ['/login']; // no redirect whitelist

// 使用钩子函数对路由进行菜单跳转
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    } else {
        document.title = '登录';
    }
    if (to.path === "/") {
        next();
    } else {
        let token = localStorage.getItem("token");
        if (token === null || token === "") {
            next();
        } else {
            next();
        }
    }
});

router.afterEach((route) => {
    // 记录操作日志
    // if (route.path != '/404' && route.path != '/login' && route.path !='/gbCollege' && route.path !='/personalTalents' &&  route.path != '/statistics' &&  route.path != '/loginNoUk') {
    //     insertPage({
    //         logPageName: route.meta.title,
    //         logPagePath: route.fullPath,
    //         logType: 1
    //     }).then(() =>{});
    // }
    NProgress.done();
});
